import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(new File("D:\\number1.txt")));
            TreeSet<Integer> treeSet = new TreeSet<>();
            String s = reader.readLine();
            while (null != s) {
                treeSet.add(Integer.parseInt(s));
                s = reader.readLine();
            }
            reader.close();
            File out = new File("D:\\number2.txt");
            if (!out.exists()) {
                boolean newFile = out.createNewFile();
                if (!newFile) {
                    System.out.println("文件创建失败！");
                    return;
                }
            }
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(out));
            for (Integer data : treeSet) {
                bufferedWriter.write(data+"\n");
            }
            bufferedWriter.flush();
            bufferedWriter.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
